/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import dao.CuaHangDAO;
import dao.QuiDinhDAO;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import pojo.CuaHang;
import pojo.HangSanXuat;
import pojo.QuyDinh;

/**
 *
 * @author Phi
 */
public class ThemQuiDinh extends javax.swing.JInternalFrame {
    //private DefaultComboBoxModel dcbm;
   // private DefaultTableModel dtm;
//    private DefaultComboBoxModel dcbm;
//    private DefaultTableModel dtm;
    /**
     * Creates new form ThemQuiDinh
     */
    public ThemQuiDinh() {
        initComponents();
        //this.dtm = new DefaultTableModel();   
    }
    public void HienThiDanhSachQuiDinh() throws Exception{
        DefaultTableModel dtm=new DefaultTableModel();
        dtm.addColumn("Ma Quy Dinh");
        dtm.addColumn("So Luong Nhap It Nhat");
        dtm.addColumn("So Luong Ton It Nhat");
        dtm.addColumn("No Khong Qua");
        dtm.addColumn("Luong Ton Sau Khi Ban");
        dtm.addColumn("Dieu Kien Thu");
        dtm.addColumn("Cua Hang");
        List<QuyDinh> ds=QuiDinhDAO.layDanhSachQuyDinh();
        dtm.setRowCount(ds.size());
        for(int i=0;i<ds.size();i++){
            QuyDinh qd=ds.get(i);
            dtm.setValueAt(qd.getMaQuyDinh(), i, 0);
            dtm.setValueAt(qd.getSoLuongNhapItNhat(), i,1);
            dtm.setValueAt(qd.getSoLuongTonItNhat(), i, 2);
            dtm.setValueAt(qd.getNoKhongQua(), i,3);
            dtm.setValueAt(qd.getLuongTonSauKhiBan(), i,4);
            dtm.setValueAt(qd.getDieuKienThu(), i,5);
            dtm.setValueAt(qd.getCuaHang().getMaCuaHang(), i, 6);
        }
        this.jtbDanhSach.setModel(dtm);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfTenQuiDinh = new javax.swing.JTextField();
        jbtThem = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jtfMa = new javax.swing.JTextField();
        jbtXoa = new javax.swing.JButton();
        jcbLua = new javax.swing.JComboBox();
        jbtTim = new javax.swing.JButton();
        jtfSoLuongNhapItNhat = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jtfNoKhongQua = new javax.swing.JTextField();
        jtfSoLuongTonItNhat = new javax.swing.JTextField();
        jtfLuongTon = new javax.swing.JTextField();
        jtfLuongTonSauKhiBan = new javax.swing.JLabel();
        jbtCapNhat = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbDanhSach = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Quản Lý Quy Định");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin qui dinh"));

        jLabel1.setText("Điều kiện thu");

        jtfTenQuiDinh.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jtfTenQuiDinhCaretUpdate(evt);
            }
        });

        jbtThem.setLabel("Thêm");
        jbtThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtThemActionPerformed(evt);
            }
        });

        jLabel2.setText("Mã qui định");

        jbtXoa.setText("Xóa");
        jbtXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtXoaActionPerformed(evt);
            }
        });

        jcbLua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbLuaActionPerformed(evt);
            }
        });

        jbtTim.setText("Tìm");
        jbtTim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtTimActionPerformed(evt);
            }
        });

        jLabel3.setText("Số lượng nhập ít nhất");

        jLabel4.setText("Số lượng tồn ít nhất");

        jLabel5.setText("Nợ không quá");

        jtfLuongTonSauKhiBan.setText("Lượng tồn sau khi bán");

        jbtCapNhat.setText("Cập Nhật");
        jbtCapNhat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCapNhatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jtfNoKhongQua, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                    .addComponent(jtfTenQuiDinh)
                    .addComponent(jtfMa))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jtfLuongTonSauKhiBan))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jtfSoLuongTonItNhat, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfSoLuongNhapItNhat, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfLuongTon, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcbLua, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbtCapNhat, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jbtTim, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbtThem, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbtXoa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jtfTenQuiDinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbtThem)
                        .addComponent(jcbLua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jtfSoLuongNhapItNhat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtfMa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtXoa)
                    .addComponent(jLabel4)
                    .addComponent(jtfSoLuongTonItNhat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbtTim)
                        .addComponent(jbtCapNhat))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jtfNoKhongQua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jtfLuongTon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jtfLuongTonSauKhiBan)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh Sách Quy Định"));

        jtbDanhSach.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jtbDanhSach.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtbDanhSachMouseClicked(evt);
            }
        });
        jtbDanhSach.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                jtbDanhSachAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });
        jScrollPane1.setViewportView(jtbDanhSach);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtbDanhSachAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_jtbDanhSachAncestorAdded
        try {
            this.HienThiDanhSachQuiDinh();
        } catch (Exception ex) {
            Logger.getLogger(ThemQuiDinh.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jtbDanhSachAncestorAdded
    public void them() throws Exception{
        String dieuKienThu=this.jtfTenQuiDinh.getText();
        
        String noKhongQua=this.jtfNoKhongQua.getText();
        int nokq=Integer.parseInt(noKhongQua);
        
        String luongTonSauKhiBan=this.jtfLuongTon.getText();
        int ltskb=Integer.parseInt(luongTonSauKhiBan);
        
        String soLuongNhapItNhat=this.jtfSoLuongNhapItNhat.getText();
        int slnin=Integer.parseInt(soLuongNhapItNhat);
        
        String soLuongTonItNhat=this.jtfSoLuongTonItNhat.getText();
        int sltin=Integer.parseInt(soLuongTonItNhat);
        
        QuyDinh qd=new QuyDinh();
        CuaHang ch=new CuaHang();
        Vector ma=new Vector();
        ma=(Vector) this.jcbLua.getSelectedItem();
        int mach=(Integer)ma.get(0);
        ch=CuaHangDAO.layThongTinCuaHang(mach);
        qd.setCuaHang(ch);
        qd.setDieuKienThu(dieuKienThu);
        qd.setLuongTonSauKhiBan(ltskb);
        qd.setNoKhongQua(nokq);
        qd.setSoLuongNhapItNhat(slnin);
        qd.setSoLuongTonItNhat(sltin);
        List<QuyDinh>ds=QuiDinhDAO.layDanhSachQuyDinh();
        int flag=0;
        for(int i=0;i<ds.size();i++){
            QuyDinh tt=ds.get(i);
            if(mach==tt.getCuaHang().getMaCuaHang()){
                JOptionPane.showMessageDialog(this,"Quy định đã tồn tại");
                flag=1;
            }
        }
        if(flag==0){
        boolean kq=QuiDinhDAO.themThongTinQuyDinh(qd);
        if(kq==false){
            JOptionPane.showMessageDialog(this,"Thêm thất bại ");         
        }
        else 
            JOptionPane.showMessageDialog(this,"Thêm thành công");
            this.HienThiDanhSachQuiDinh();
        }
    }
    
     public void xoa_CapNhat() throws Exception{
        int dong=this.jtbDanhSach.getSelectedRow();
        int maQuyDinh=(Integer) this.jtbDanhSach.getValueAt(dong, 0);
        boolean kq=QuiDinhDAO.xoaQuyDinh(maQuyDinh);
    }
     
      public void them_CapNhat() throws Exception{
        String dieuKienThu=this.jtfTenQuiDinh.getText();
        
        String noKhongQua=this.jtfNoKhongQua.getText();
        int nokq=Integer.parseInt(noKhongQua);
        
        String luongTonSauKhiBan=this.jtfLuongTon.getText();
        int ltskb=Integer.parseInt(luongTonSauKhiBan);
        
        String soLuongNhapItNhat=this.jtfSoLuongNhapItNhat.getText();
        int slnin=Integer.parseInt(soLuongNhapItNhat);
        
        String soLuongTonItNhat=this.jtfSoLuongTonItNhat.getText();
        int sltin=Integer.parseInt(soLuongTonItNhat);
        
        QuyDinh qd=new QuyDinh();
        CuaHang ch=new CuaHang();
        Vector ma=new Vector();
        ma=(Vector) this.jcbLua.getSelectedItem();
        int mach=(Integer)ma.get(0);
        ch=CuaHangDAO.layThongTinCuaHang(mach);
        qd.setCuaHang(ch);
        qd.setDieuKienThu(dieuKienThu);
        qd.setLuongTonSauKhiBan(ltskb);
        qd.setNoKhongQua(nokq);
        qd.setSoLuongNhapItNhat(slnin);
        qd.setSoLuongTonItNhat(sltin);
        boolean kq=QuiDinhDAO.themThongTinQuyDinh(qd);
        if(kq==false){
            JOptionPane.showMessageDialog(this,"Cập nhật thất bại ");         
        }
        else 
            JOptionPane.showMessageDialog(this,"Cập nhật thành công");
            this.HienThiDanhSachQuiDinh();
    }
      
      public void capnhat() throws Exception{
          this.xoa_CapNhat();
          this.them_CapNhat();
    }
    private void jbtThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtThemActionPerformed
        try {
            this.them();
        } catch (Exception ex) {
            Logger.getLogger(ThemQuiDinh.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jbtThemActionPerformed
    public void xoa() throws Exception{
        int dong=this.jtbDanhSach.getSelectedRow();
        int maQuyDinh=(Integer) this.jtbDanhSach.getValueAt(dong, 0);
        boolean kq=QuiDinhDAO.xoaQuyDinh(maQuyDinh);
        if(kq==false){
            JOptionPane.showMessageDialog(this,"Xoá thất bại ");         
        }
        else 
            JOptionPane.showMessageDialog(this,"Xoá thành công");
            this.HienThiDanhSachQuiDinh();
    }
    private void jbtXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtXoaActionPerformed
        try {
            this.xoa();
        } catch (Exception ex) {
            Logger.getLogger(ThemQuiDinh.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jbtXoaActionPerformed
     public void timKiem() {
        try {                    
            Vector vt=new Vector();
            vt = (Vector) this.jcbLua.getSelectedItem();
            int maCuaHang = (Integer) vt.get(0);
            String dieuKienThu = this.jtfTenQuiDinh.getText();
            List<QuyDinh> ds=QuiDinhDAO.timKiemQuyDinh(dieuKienThu,maCuaHang);
            DefaultTableModel dtm = new DefaultTableModel();
            dtm.addColumn("Ma Quy Dinh");
            dtm.addColumn("So Luong Nhap It Nhat");
            dtm.addColumn("So Luong Ton It Nhat");
            dtm.addColumn("No Khong Qua");
            dtm.addColumn("Luong Ton Sau Khi Ban");
            dtm.addColumn("Dieu Kien Thu");
            dtm.addColumn("Cua Hang");
            //dtm.setRowCount(ds.size());
            for(int i=0;i<ds.size();i++){
            QuyDinh qd=ds.get(i);
            Vector vt1 = new Vector();
                vt1.add(qd.getMaQuyDinh());
                vt1.add(qd.getSoLuongNhapItNhat());
                vt1.add(qd.getSoLuongTonItNhat());
                vt1.add(qd.getNoKhongQua());
                vt1.add(qd.getLuongTonSauKhiBan());
                vt1.add(qd.getDieuKienThu());    
                vt1.add(qd.getCuaHang().getMaCuaHang());
                dtm.addRow(vt1);
        }
            this.jtbDanhSach.setModel(dtm);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
     
    }
    private void jcbLuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbLuaActionPerformed
       this.timKiem();
    }//GEN-LAST:event_jcbLuaActionPerformed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
         try {
            DefaultComboBoxModel dcbm=new DefaultComboBoxModel();
            List<CuaHang> ds=CuaHangDAO.layDanhSachCuaHang();
            for(int i=0; i<ds.size(); i++){ 
                CuaHang ch=ds.get(i); 
                Vector vt = new Vector();
                vt.add(ch.getMaCuaHang());
                vt.add(ch.getTenCuaHang());
                dcbm.addElement(vt);
            }
            this.jcbLua.setModel(dcbm);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_formInternalFrameOpened

    private void jbtCapNhatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCapNhatActionPerformed
        try {
            this.capnhat();
        } catch (Exception ex) {
            Logger.getLogger(ThemQuiDinh.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jbtCapNhatActionPerformed

    private void jbtTimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtTimActionPerformed
        this.timKiem();
    }//GEN-LAST:event_jbtTimActionPerformed

    private void jtbDanhSachMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtbDanhSachMouseClicked
        int dong=this.jtbDanhSach.getSelectedRow();
        String dieuKienThu=this.jtbDanhSach.getValueAt(dong, 5).toString();
       // String maQuiDinh=this.jtbDanhSach.getValueAt(dong, 0).toString();
        String soLuongNhapItNhat=this.jtbDanhSach.getValueAt(dong, 1).toString();
        String soLuongTonItNhat=this.jtbDanhSach.getValueAt(dong, 2).toString();
        String noKhongQua=this.jtbDanhSach.getValueAt(dong,3).toString();
        String luongTonSauKhiBan=this.jtbDanhSach.getValueAt(dong,4).toString();
        this.jtfTenQuiDinh.setText(dieuKienThu);
        //this.jtfMa.setText(maQuiDinh);
        this.jtfSoLuongNhapItNhat.setText(soLuongNhapItNhat);
        this.jtfSoLuongTonItNhat.setText(soLuongTonItNhat);
        this.jtfNoKhongQua.setText(noKhongQua);
        this.jtfLuongTon.setText(luongTonSauKhiBan);
    }//GEN-LAST:event_jtbDanhSachMouseClicked

    private void jtfTenQuiDinhCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jtfTenQuiDinhCaretUpdate
        //this.timKiem();
    }//GEN-LAST:event_jtfTenQuiDinhCaretUpdate
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtCapNhat;
    private javax.swing.JButton jbtThem;
    private javax.swing.JButton jbtTim;
    private javax.swing.JButton jbtXoa;
    private javax.swing.JComboBox jcbLua;
    private javax.swing.JTable jtbDanhSach;
    private javax.swing.JTextField jtfLuongTon;
    private javax.swing.JLabel jtfLuongTonSauKhiBan;
    private javax.swing.JTextField jtfMa;
    private javax.swing.JTextField jtfNoKhongQua;
    private javax.swing.JTextField jtfSoLuongNhapItNhat;
    private javax.swing.JTextField jtfSoLuongTonItNhat;
    private javax.swing.JTextField jtfTenQuiDinh;
    // End of variables declaration//GEN-END:variables
}
